﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using HYSoft.IDAL;
using Maticsoft.DBUtility;//Please add references

namespace HYSoft.SQLServerDAL
{
    /// <summary>
    /// 数据访问类:View_Log
    /// </summary>
    public partial class View_Log : IView_Log
    {
        public View_Log()
        { }
        #region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string m_area_name, string m_brd_addr, string m_bs_add, int m_brd_mac, int m_log_id, int m_bs_id, int m_alra_deal, int m_brd_log_time, int m_send_sms, int m_brd_log_year, string m_msg, int m_alar_stat)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from View_Log");
            strSql.Append(" where m_area_name=@m_area_name and m_brd_addr=@m_brd_addr and m_bs_add=@m_bs_add and m_brd_mac=@m_brd_mac and m_log_id=@m_log_id and m_bs_id=@m_bs_id and m_alra_deal=@m_alra_deal and m_brd_log_time=@m_brd_log_time and m_send_sms=@m_send_sms and m_brd_log_year=@m_brd_log_year and m_msg=@m_msg and m_alar_stat=@m_alar_stat ");
            SqlParameter[] parameters = {
					new SqlParameter("@m_area_name", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_addr", SqlDbType.VarChar,255),
					new SqlParameter("@m_bs_add", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_mac", SqlDbType.Int,4),
					new SqlParameter("@m_log_id", SqlDbType.Int,4),
					new SqlParameter("@m_bs_id", SqlDbType.Int,4),
					new SqlParameter("@m_alra_deal", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_time", SqlDbType.Int,4),
					new SqlParameter("@m_send_sms", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_year", SqlDbType.Int,4),
					new SqlParameter("@m_msg", SqlDbType.VarChar,255),
					new SqlParameter("@m_alar_stat", SqlDbType.Int,4)			};
            parameters[0].Value = m_area_name;
            parameters[1].Value = m_brd_addr;
            parameters[2].Value = m_bs_add;
            parameters[3].Value = m_brd_mac;
            parameters[4].Value = m_log_id;
            parameters[5].Value = m_bs_id;
            parameters[6].Value = m_alra_deal;
            parameters[7].Value = m_brd_log_time;
            parameters[8].Value = m_send_sms;
            parameters[9].Value = m_brd_log_year;
            parameters[10].Value = m_msg;
            parameters[11].Value = m_alar_stat;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(HYSoft.Model.View_Log model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into View_Log(");
            strSql.Append("m_area_name,m_brd_addr,m_bs_add,m_brd_mac,m_log_id,m_bs_id,m_alra_deal,m_brd_log_time,m_send_sms,m_brd_log_year,m_msg,m_alar_stat)");
            strSql.Append(" values (");
            strSql.Append("@m_area_name,@m_brd_addr,@m_bs_add,@m_brd_mac,@m_log_id,@m_bs_id,@m_alra_deal,@m_brd_log_time,@m_send_sms,@m_brd_log_year,@m_msg,@m_alar_stat)");
            SqlParameter[] parameters = {
					new SqlParameter("@m_area_name", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_addr", SqlDbType.VarChar,255),
					new SqlParameter("@m_bs_add", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_mac", SqlDbType.Int,4),
					new SqlParameter("@m_log_id", SqlDbType.Int,4),
					new SqlParameter("@m_bs_id", SqlDbType.Int,4),
					new SqlParameter("@m_alra_deal", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_time", SqlDbType.Int,4),
					new SqlParameter("@m_send_sms", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_year", SqlDbType.Int,4),
					new SqlParameter("@m_msg", SqlDbType.VarChar,255),
					new SqlParameter("@m_alar_stat", SqlDbType.Int,4)};
            parameters[0].Value = model.m_area_name;
            parameters[1].Value = model.m_brd_addr;
            parameters[2].Value = model.m_bs_add;
            parameters[3].Value = model.m_brd_mac;
            parameters[4].Value = model.m_log_id;
            parameters[5].Value = model.m_bs_id;
            parameters[6].Value = model.m_alra_deal;
            parameters[7].Value = model.m_brd_log_time;
            parameters[8].Value = model.m_send_sms;
            parameters[9].Value = model.m_brd_log_year;
            parameters[10].Value = model.m_msg;
            parameters[11].Value = model.m_alar_stat;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(HYSoft.Model.View_Log model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update View_Log set ");
            strSql.Append("m_area_name=@m_area_name,");
            strSql.Append("m_brd_addr=@m_brd_addr,");
            strSql.Append("m_bs_add=@m_bs_add,");
            strSql.Append("m_brd_mac=@m_brd_mac,");
            strSql.Append("m_log_id=@m_log_id,");
            strSql.Append("m_bs_id=@m_bs_id,");
            strSql.Append("m_alra_deal=@m_alra_deal,");
            strSql.Append("m_brd_log_time=@m_brd_log_time,");
            strSql.Append("m_send_sms=@m_send_sms,");
            strSql.Append("m_brd_log_year=@m_brd_log_year,");
            strSql.Append("m_msg=@m_msg,");
            strSql.Append("m_alar_stat=@m_alar_stat");
            strSql.Append(" where m_area_name=@m_area_name and m_brd_addr=@m_brd_addr and m_bs_add=@m_bs_add and m_brd_mac=@m_brd_mac and m_log_id=@m_log_id and m_bs_id=@m_bs_id and m_alra_deal=@m_alra_deal and m_brd_log_time=@m_brd_log_time and m_send_sms=@m_send_sms and m_brd_log_year=@m_brd_log_year and m_msg=@m_msg and m_alar_stat=@m_alar_stat ");
            SqlParameter[] parameters = {
					new SqlParameter("@m_area_name", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_addr", SqlDbType.VarChar,255),
					new SqlParameter("@m_bs_add", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_mac", SqlDbType.Int,4),
					new SqlParameter("@m_log_id", SqlDbType.Int,4),
					new SqlParameter("@m_bs_id", SqlDbType.Int,4),
					new SqlParameter("@m_alra_deal", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_time", SqlDbType.Int,4),
					new SqlParameter("@m_send_sms", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_year", SqlDbType.Int,4),
					new SqlParameter("@m_msg", SqlDbType.VarChar,255),
					new SqlParameter("@m_alar_stat", SqlDbType.Int,4)};
            parameters[0].Value = model.m_area_name;
            parameters[1].Value = model.m_brd_addr;
            parameters[2].Value = model.m_bs_add;
            parameters[3].Value = model.m_brd_mac;
            parameters[4].Value = model.m_log_id;
            parameters[5].Value = model.m_bs_id;
            parameters[6].Value = model.m_alra_deal;
            parameters[7].Value = model.m_brd_log_time;
            parameters[8].Value = model.m_send_sms;
            parameters[9].Value = model.m_brd_log_year;
            parameters[10].Value = model.m_msg;
            parameters[11].Value = model.m_alar_stat;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string m_area_name, string m_brd_addr, string m_bs_add, int m_brd_mac, int m_log_id, int m_bs_id, int m_alra_deal, int m_brd_log_time, int m_send_sms, int m_brd_log_year, string m_msg, int m_alar_stat)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from View_Log ");
            strSql.Append(" where m_area_name=@m_area_name and m_brd_addr=@m_brd_addr and m_bs_add=@m_bs_add and m_brd_mac=@m_brd_mac and m_log_id=@m_log_id and m_bs_id=@m_bs_id and m_alra_deal=@m_alra_deal and m_brd_log_time=@m_brd_log_time and m_send_sms=@m_send_sms and m_brd_log_year=@m_brd_log_year and m_msg=@m_msg and m_alar_stat=@m_alar_stat ");
            SqlParameter[] parameters = {
					new SqlParameter("@m_area_name", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_addr", SqlDbType.VarChar,255),
					new SqlParameter("@m_bs_add", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_mac", SqlDbType.Int,4),
					new SqlParameter("@m_log_id", SqlDbType.Int,4),
					new SqlParameter("@m_bs_id", SqlDbType.Int,4),
					new SqlParameter("@m_alra_deal", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_time", SqlDbType.Int,4),
					new SqlParameter("@m_send_sms", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_year", SqlDbType.Int,4),
					new SqlParameter("@m_msg", SqlDbType.VarChar,255),
					new SqlParameter("@m_alar_stat", SqlDbType.Int,4)			};
            parameters[0].Value = m_area_name;
            parameters[1].Value = m_brd_addr;
            parameters[2].Value = m_bs_add;
            parameters[3].Value = m_brd_mac;
            parameters[4].Value = m_log_id;
            parameters[5].Value = m_bs_id;
            parameters[6].Value = m_alra_deal;
            parameters[7].Value = m_brd_log_time;
            parameters[8].Value = m_send_sms;
            parameters[9].Value = m_brd_log_year;
            parameters[10].Value = m_msg;
            parameters[11].Value = m_alar_stat;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HYSoft.Model.View_Log GetModel(string m_area_name, string m_brd_addr, string m_bs_add, int m_brd_mac, int m_log_id, int m_bs_id, int m_alra_deal, int m_brd_log_time, int m_send_sms, int m_brd_log_year, string m_msg, int m_alar_stat)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 m_area_name,m_brd_addr,m_bs_add,m_brd_mac,m_log_id,m_bs_id,m_alra_deal,m_brd_log_time,m_send_sms,m_brd_log_year,m_msg,m_alar_stat from View_Log ");
            strSql.Append(" where m_area_name=@m_area_name and m_brd_addr=@m_brd_addr and m_bs_add=@m_bs_add and m_brd_mac=@m_brd_mac and m_log_id=@m_log_id and m_bs_id=@m_bs_id and m_alra_deal=@m_alra_deal and m_brd_log_time=@m_brd_log_time and m_send_sms=@m_send_sms and m_brd_log_year=@m_brd_log_year and m_msg=@m_msg and m_alar_stat=@m_alar_stat ");
            SqlParameter[] parameters = {
					new SqlParameter("@m_area_name", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_addr", SqlDbType.VarChar,255),
					new SqlParameter("@m_bs_add", SqlDbType.VarChar,255),
					new SqlParameter("@m_brd_mac", SqlDbType.Int,4),
					new SqlParameter("@m_log_id", SqlDbType.Int,4),
					new SqlParameter("@m_bs_id", SqlDbType.Int,4),
					new SqlParameter("@m_alra_deal", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_time", SqlDbType.Int,4),
					new SqlParameter("@m_send_sms", SqlDbType.Int,4),
					new SqlParameter("@m_brd_log_year", SqlDbType.Int,4),
					new SqlParameter("@m_msg", SqlDbType.VarChar,255),
					new SqlParameter("@m_alar_stat", SqlDbType.Int,4)			};
            parameters[0].Value = m_area_name;
            parameters[1].Value = m_brd_addr;
            parameters[2].Value = m_bs_add;
            parameters[3].Value = m_brd_mac;
            parameters[4].Value = m_log_id;
            parameters[5].Value = m_bs_id;
            parameters[6].Value = m_alra_deal;
            parameters[7].Value = m_brd_log_time;
            parameters[8].Value = m_send_sms;
            parameters[9].Value = m_brd_log_year;
            parameters[10].Value = m_msg;
            parameters[11].Value = m_alar_stat;

            HYSoft.Model.View_Log model = new HYSoft.Model.View_Log();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HYSoft.Model.View_Log DataRowToModel(DataRow row)
        {
            HYSoft.Model.View_Log model = new HYSoft.Model.View_Log();
            if (row != null)
            {
                if (row["m_area_name"] != null)
                {
                    model.m_area_name = row["m_area_name"].ToString();
                }
                if (row["m_brd_addr"] != null)
                {
                    model.m_brd_addr = row["m_brd_addr"].ToString();
                }
                if (row["m_bs_add"] != null)
                {
                    model.m_bs_add = row["m_bs_add"].ToString();
                }
                if (row["m_brd_mac"] != null && row["m_brd_mac"].ToString() != "")
                {
                    model.m_brd_mac = int.Parse(row["m_brd_mac"].ToString());
                }
                if (row["m_log_id"] != null && row["m_log_id"].ToString() != "")
                {
                    model.m_log_id = int.Parse(row["m_log_id"].ToString());
                }
                if (row["m_bs_id"] != null && row["m_bs_id"].ToString() != "")
                {
                    model.m_bs_id = int.Parse(row["m_bs_id"].ToString());
                }
                if (row["m_alra_deal"] != null && row["m_alra_deal"].ToString() != "")
                {
                    model.m_alra_deal = int.Parse(row["m_alra_deal"].ToString());
                }
                if (row["m_brd_log_time"] != null && row["m_brd_log_time"].ToString() != "")
                {
                    model.m_brd_log_time = int.Parse(row["m_brd_log_time"].ToString());
                }
                if (row["m_send_sms"] != null && row["m_send_sms"].ToString() != "")
                {
                    model.m_send_sms = int.Parse(row["m_send_sms"].ToString());
                }
                if (row["m_brd_log_year"] != null && row["m_brd_log_year"].ToString() != "")
                {
                    model.m_brd_log_year = int.Parse(row["m_brd_log_year"].ToString());
                }
                if (row["m_msg"] != null)
                {
                    model.m_msg = row["m_msg"].ToString();
                }
                if (row["m_alar_stat"] != null && row["m_alar_stat"].ToString() != "")
                {
                    model.m_alar_stat = int.Parse(row["m_alar_stat"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select m_area_name,m_brd_addr,m_bs_add,m_brd_mac,m_log_id,m_bs_id,m_alra_deal,m_brd_log_time,m_send_sms,m_brd_log_year,m_msg,m_alar_stat ");
            strSql.Append(" FROM View_Log ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" m_area_name,m_brd_addr,m_bs_add,m_brd_mac,m_log_id,m_bs_id,m_alra_deal,m_brd_log_time,m_send_sms,m_brd_log_year,m_msg,m_alar_stat ");
            strSql.Append(" FROM View_Log ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM View_Log ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.m_alar_stat desc");
            }
            strSql.Append(")AS Row, T.*  from View_Log T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "View_Log";
            parameters[1].Value = "m_alar_stat";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}